package com.bsj.power.pls.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.dto.group.GroupDTO;
import com.bsj.power.common.def.vo.pls.GroupTreeVO;
import com.bsj.power.common.def.vo.pls.GroupVO;
import com.bsj.power.pls.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description GroupController
 * @time 2024/4/25 19:20
 */
@RestController
@RequestMapping("/group")
//@SaCheckPermission("/pls/group")
public class GroupController {


    @Autowired
    private GroupService groupService;

    /**
     * 添加组织
     *
     * @param groupDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/25 19:40
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody GroupDTO groupDTO) {
        return groupService.addGroup(groupDTO);
    }

    /**
     * 删除组织
     *
     * @param groupId
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/25 19:41
     */
    @PostMapping("/delete/{groupId}")
    public JsonResult delete(@PathVariable("groupId") Integer groupId) {
        return groupService.deleteGroup(groupId);
    }

    /**
     * 修改组织
     *
     * @param groupDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/25 19:41
     */
    @PostMapping("/update")
    public JsonResult update(@Validated @RequestBody GroupDTO groupDTO) {
        return groupService.updateGroup(groupDTO);
    }

    /**
     * 获取单个组织信息
     *
     * @param groupId
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.pls.GroupVO>
     * @author ljx
     * @time 2024/4/25 19:41
     */
    @GetMapping("/getById/{groupId}")
    public JsonResult<GroupVO> getById(@PathVariable("groupId") Integer groupId) {
        return JsonResult.success(groupService.getGroupById(groupId));
    }

    /**
     * 获取组织树
     *
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.pls.GroupTreeVO>>
     * @author ljx
     * @time 2024/4/25 19:41
     */
    @GetMapping("/getGroupTree")
    public JsonResult<List<GroupTreeVO>> getGroupTree() {
        return JsonResult.success(groupService.getGroupTree());
    }

}
